//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package ui;

import templet.Code;
import xml.XmlUtil;

import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class CodeUtil extends JFrame {
    private JButton jButton1;
    private JButton jButton2;
    private JButton jButton6;
    private JButton jButton7;
    private JComboBox jComboBox1;
    private JLabel jLabel1;
    private JLabel jLabel10;
    private JLabel jLabel11;
    private JLabel jLabel4;
    private JLabel jLabel5;
    private JLabel jLabel6;
    private JLabel jLabel7;
    private JLabel jLabel8;
    private JLabel jLabel9;
    private JSeparator jSeparator1;
    private JSeparator jSeparator2;
    private JTextField jTextField10;
    private JTextField jTextField11;
    private JTextField jTextField12;
    private JTextField jTextField4;
    private JTextField jTextField5;
    private JTextField jTextField6;
    private JTextField jTextField7;
    private JTextField jTextField8;
    private JTextField jTextField9;
    private JLabel databaseLabel;
    
    public CodeUtil() {
        this.initComponents();
    }
    
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                (new CodeUtil()).setVisible(true);
            }
        });
    }
    
    private void initComponents() {
        this.jLabel1 = new JLabel();
        this.jLabel4 = new JLabel();
        this.jSeparator1 = new JSeparator();
        this.jTextField4 = new JTextField();
        this.jLabel5 = new JLabel();
        this.jTextField5 = new JTextField();
        this.jSeparator2 = new JSeparator();
        this.jLabel6 = new JLabel();
        this.jTextField6 = new JTextField();
        this.jLabel7 = new JLabel();
        this.jTextField7 = new JTextField();
        this.jLabel8 = new JLabel();
        this.jTextField8 = new JTextField();
        this.jLabel9 = new JLabel();
        this.jTextField9 = new JTextField();
        this.jButton1 = new JButton();
        this.jButton2 = new JButton();
        this.jButton6 = new JButton();
        this.jButton7 = new JButton();
        this.databaseLabel = new JLabel();
        this.jTextField10 = new JTextField();
        this.jLabel10 = new JLabel();
        this.jTextField11 = new JTextField();
        this.jLabel11 = new JLabel();
        this.jTextField12 = new JTextField();
        this.jComboBox1 = new JComboBox();
        this.setDefaultCloseOperation(3);
        this.setTitle("黑马程序员代码生成器2.4");
        this.addWindowListener(new WindowAdapter() {
            public void windowActivated(WindowEvent evt) {
                CodeUtil.this.formWindowActivated(evt);
            }
            
            public void windowOpened(WindowEvent evt) {
                CodeUtil.this.formWindowOpened(evt);
            }
            
            public void windowClosing(WindowEvent evt) {
                CodeUtil.this.formWindowClosing(evt);
            }
        });
        this.jLabel1.setText("模板");
        this.jLabel4.setText("结构文档路径");
        this.jLabel5.setText("代码生成路径");
        this.jLabel6.setText("项目名（英文）");
        this.jLabel7.setText("项目中文名称");
        this.jLabel8.setText("包名");
        this.jLabel9.setText("作者");
        this.jButton1.setText("生成代码");
        this.jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                CodeUtil.this.jButton1ActionPerformed(evt);
            }
        });
        this.jButton2.setText("关闭");
        this.jButton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                CodeUtil.this.jButton2ActionPerformed(evt);
            }
        });
        this.jButton6.setText("选择");
        this.jButton6.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                CodeUtil.this.jButton6ActionPerformed(evt);
            }
        });
        this.jButton7.setText("选择");
        this.jButton7.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                CodeUtil.this.jButton7ActionPerformed(evt);
            }
        });
        this.databaseLabel.setText("databaseLabel");
        this.jLabel10.setText("用户名");
        this.jLabel11.setText("密码");
        this.jComboBox1.setModel(new DefaultComboBoxModel(new String[]{"--请选择模板--"}));
        GroupLayout layout = new GroupLayout(this.getContentPane());
        this.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(Alignment.LEADING).addComponent(this.jSeparator2, -1, 543, 32767).addComponent(this.jSeparator1, Alignment.TRAILING, -1, 543, 32767).addGroup(Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(26, 26, 26).addGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(this.jLabel4).addGroup(layout.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED).addComponent(this.jLabel5)))).addGroup(layout.createSequentialGroup().addGap(25, 25, 25).addGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(this.jLabel6).addComponent(this.jLabel8).addComponent(this.jLabel7).addComponent(this.jLabel9).addComponent(this.databaseLabel).addComponent(this.jLabel10)))).addGap(0, 0, 0).addGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(this.jTextField11, -2, 104, -2).addGap(18, 18, 18).addComponent(this.jLabel11).addGap(36, 36, 36).addComponent(this.jTextField12, -1, 118, 32767)).addComponent(this.jTextField10, -1, 300, 32767).addGroup(Alignment.TRAILING, layout.createSequentialGroup().addComponent(this.jButton1).addPreferredGap(ComponentPlacement.RELATED, 140, 32767).addComponent(this.jButton2, -2, 79, -2)).addComponent(this.jTextField4, -1, 300, 32767).addComponent(this.jTextField5, -1, 300, 32767).addComponent(this.jTextField6, -1, 300, 32767).addComponent(this.jTextField7, -1, 300, 32767).addComponent(this.jTextField8, -1, 300, 32767).addComponent(this.jTextField9, -1, 300, 32767)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.TRAILING, false).addComponent(this.jButton7, Alignment.LEADING, 0, 0, 32767).addComponent(this.jButton6, Alignment.LEADING, -1, 73, 32767)).addGap(54, 54, 54)).addGroup(Alignment.TRAILING, layout.createSequentialGroup().addGap(27, 27, 27).addComponent(this.jLabel1).addGap(57, 57, 57).addComponent(this.jComboBox1, -2, 299, -2).addGap(136, 136, 136)));
        layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(96, 96, 96).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jComboBox1, -2, -1, -2).addComponent(this.jLabel1)).addGap(18, 18, 18).addComponent(this.jSeparator1, -2, 10, -2).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel4).addComponent(this.jTextField4).addComponent(this.jButton6)).addGap(15, 15, 15).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel5).addComponent(this.jTextField5).addComponent(this.jButton7)).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(this.jSeparator2, -2, 10, -2).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel6).addComponent(this.jTextField6)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(this.jLabel8).addComponent(this.jTextField7)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel7).addComponent(this.jTextField8)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jTextField9).addComponent(this.jLabel9)).addGap(18, 18, 18).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.databaseLabel).addComponent(this.jTextField10)).addGap(18, 18, 18).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jLabel10).addComponent(this.jTextField11, -2, -1, -2).addComponent(this.jLabel11).addComponent(this.jTextField12, -2, -1, -2)).addGap(26, 26, 26).addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jButton2).addComponent(this.jButton1)).addGap(24, 24, 24)));
        this.pack();
    }
    
    private void formWindowClosing(WindowEvent evt) {
        this.dispose();
        System.exit(0);
    }
    
    private void formWindowOpened(WindowEvent evt) {
        this.setLocationRelativeTo((Component) null);
        File directory = new File((new File("")).getAbsolutePath() + "\\模板");
        File[] listFiles = directory.listFiles();
        if (listFiles != null) {
            File[] var7 = listFiles;
            int var6 = listFiles.length;
            
            for (int var5 = 0; var5 < var6; ++var5) {
                File f = var7[var5];
                if (f.isDirectory()) {
                    this.jComboBox1.addItem(f.getName());
                }
            }
        }
        
        this.jTextField4.setText((new File("")).getAbsolutePath() + "\\db");
        Map<String, String> publicMap = XmlUtil.read("publicMap.xml");
        if (publicMap != null && publicMap.size() > 0) {
            this.jTextField6.setText((String) publicMap.get("project"));
            this.jTextField7.setText((String) publicMap.get("package"));
            this.jTextField8.setText((String) publicMap.get("projectComment"));
            this.jTextField9.setText((String) publicMap.get("author"));
        }
        
    }
    
    private void formWindowActivated(WindowEvent evt) {
    }
    
    private void jButton2ActionPerformed(ActionEvent evt) {
        System.exit(0);
    }
    
    public void setDbInfo(String dbName, String dbuser, String dbpassword) {
        this.jTextField10.setText(dbName);
        this.jTextField11.setText(dbuser);
        this.jTextField12.setText(dbpassword);
    }
    
    private void jButton1ActionPerformed(ActionEvent evt) {
        this.jButton1.setEnabled(false);
        this.jButton1.setText("代码生成中...");
        Thread t = new Thread(new Runnable() {
            public void run() {
                try {
                    Map<String, String> pathMap = new HashMap();
                    String basePath = (new File("")).getAbsolutePath() + "\\模板\\" + CodeUtil.this.jComboBox1.getSelectedItem();
                    pathMap.put("templetPath", basePath);
                    pathMap.put("projectTempletPath", basePath + "\\工程模板");
                    pathMap.put("tablleTempletPath", basePath + "\\表级模板");
                    pathMap.put("columnTempletPath", basePath + "\\列级模板");
                    pathMap.put("xmlPath", CodeUtil.this.jTextField4.getText());
                    pathMap.put("codePath", CodeUtil.this.jTextField5.getText());
                    Map<String, String> publicMap = new HashMap();
                    publicMap.put("project", CodeUtil.this.jTextField6.getText());
                    publicMap.put("package", CodeUtil.this.jTextField7.getText());
                    publicMap.put("projectComment", CodeUtil.this.jTextField8.getText());
                    publicMap.put("author", CodeUtil.this.jTextField9.getText());
                    publicMap.put("db", CodeUtil.this.jTextField10.getText());
                    publicMap.put("dbuser", CodeUtil.this.jTextField11.getText());
                    publicMap.put("dbpassword", CodeUtil.this.jTextField12.getText());
                    String s = CodeUtil.this.jTextField7.getText().replace(".", ",");
                    String[] paths = s.split(",");
                    
                    for (int i = 0; i < paths.length; ++i) {
                        publicMap.put("path_" + String.valueOf(i + 1), paths[i]);
                    }
                    
                    publicMap.put("path_all", s.replace(",", "/"));
                    XmlUtil.write(publicMap, "publicMap.xml");
                    Code.create(pathMap, publicMap);
                    JOptionPane.showMessageDialog((Component) null, "代码生成成功", "提示", -1);
                } catch (Exception var7) {
                    var7.printStackTrace();
                    JOptionPane.showMessageDialog((Component) null, "发生错误", "错误详情请查看error.log", 1);
                }
                
                CodeUtil.this.jButton1.setEnabled(true);
                CodeUtil.this.jButton1.setText("生成代码");
            }
        });
        t.start();
    }
    
    private void jButton7ActionPerformed(ActionEvent evt) {
        this.jTextField5.setText(this.selectPath("选择代码生成路径"));
    }
    
    private void jButton6ActionPerformed(ActionEvent evt) {
        this.jTextField4.setText(this.selectPath("选择结构文档路径"));
    }
    
    private void jButton4ActionPerformed(ActionEvent evt) {
    }
    
    private String selectPath(String title) {
        JFileChooser jfc = new JFileChooser();
        jfc.setFileSelectionMode(1);
        jfc.showDialog(new JLabel(), title);
        File file = jfc.getSelectedFile();
        return file == null ? null : file.getPath();
    }
}
